package com.panda.cn.service.impl;


import cn.hutool.core.util.ObjUtil;
import cn.hutool.json.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.panda.cn.config.exception.RestfulException;
import com.panda.cn.entity.SysJobEntity;
import com.panda.cn.entity.SysOperLogEntity;
import com.panda.cn.entity.SysRoleEntity;
import com.panda.cn.mapper.SysOperLogMapper;
import com.panda.cn.service.SysOperLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 系统岗位服务impl
 *
 * @author Yanmh
 * @date 2022/09/20
 */
@Slf4j
@Service
@DS("sys")
public class SysOperLogServiceImpl implements SysOperLogService {
    
    @Resource
    private SysOperLogMapper sysOperLogMapper;
    
    
    /**
     * 页面列表
     *
     * @param params 参数个数
     * @return {@link List}
     */
    @Override
    public Page<SysOperLogEntity>  pageList(JSONObject params) {
        Long current = params.getLong("current");
        Long size = params.getLong("size");
        log.info("当前页数>>>{}", current);
        log.info("当前页显示数量>>>{}", size);
        Page<SysOperLogEntity> page = new Page<>(current, size);
        LambdaQueryWrapper<SysOperLogEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(SysOperLogEntity::getModul, params.getStr("modul"))
                .like(SysOperLogEntity::getMessage, params.getStr("message"))
                .like(SysOperLogEntity::getIp, params.getStr("ip"))
                .orderByDesc(SysOperLogEntity::getCreateTime);
        return  sysOperLogMapper.selectPage(page, queryWrapper);
    }
    
    /**
     * 删除
     *
     * @param params 参数个数
     * @return {@link Long}
     */
    @Override
    public Long remove(List<Long> params) {
        // 验证
        if (ObjUtil.isNull(params) || params.size() == 0)
            throw new RestfulException("唯一编码缺失");
        int delete = sysOperLogMapper.deleteBatchIds(params);
        return Long.valueOf(delete);
    }
}
